package com.cxf.windex.rest.minab;

import com.cxf.windex.base.msg.ObjectRestResponse;
import com.cxf.windex.base.msg.TableResultResponse;
import com.cxf.windex.base.rest.BaseRestController;
import com.cxf.windex.biz.BShopBiz;
import com.cxf.windex.biz.JsUserBiz;
import com.cxf.windex.entity.BShop;
import com.cxf.windex.entity.JsUser;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: business_needs
 * @description: 店铺
 * @author: chenxf
 * @create: 2018-10-16 14:39
 **/
@Api(tags = {"村广通[小程序-商] - 店铺接口"})
@Controller
@RequestMapping("userb/shop")
public class BShopController extends BaseRestController<BShopBiz,BShop>  {

  @Autowired
  private JsUserBiz jsUserBiz;

  @ApiOperation(value = "获取当前用户店铺信息", notes = "获取当前用户店铺信息")
  @RequestMapping(value = "/getInfo", method = RequestMethod.GET)
  @ApiImplicitParams({
      @ApiImplicitParam(name = "wxopenid", value = "微信 openID", required = true, paramType = "query", dataType = "String")
  })
  @ResponseBody
  public ObjectRestResponse getInfo(String wxopenid){
    BShop entity=baseBiz.getInfo(wxopenid);
    if(entity==null){
      return new ObjectRestResponse("店铺不存在").rel(false);
    }
     return new ObjectRestResponse("查询成功").rel(true).result(entity);
  }

  @ApiOperation(value = "保存店铺", notes = "保存店铺")
  @RequestMapping(value = "/save", method = RequestMethod.POST)
  @ResponseBody
  public ObjectRestResponse save(BShop entity){
    baseBiz.save(entity);

    JsUser jsUser=jsUserBiz.queryByOpenid(entity.getWxopenid());
    if(jsUser!=null){
      // 更新 用户表姓名 状态为1 正式用户
      jsUserBiz.updateSelectiveById(JsUser.builder().id(jsUser.getId()).name(entity.getName()).status("1").build());
    }

    return new ObjectRestResponse("保存成功").rel(true);
  }
}
